package com.erp.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class GmtMetaObjectHandler implements MetaObjectHandler {

    @Override//入库 created
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        /**
         *   this.setFieldValByName(arg1,arg2,arg3 )
         *   arg1: 自动填充的字段名称
         *   arg2: 自动填充 的值
         *   arg3: metaObject固定写法
         */
        this.setFieldValByName("gmtCreate", date, metaObject);
        this.setFieldValByName("gmtModified", date, metaObject);
    }

    @Override//更新调用 updated
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtModified", new Date(), metaObject);
    }
}

